# coding=utf-8

from Common.common import *
import requests
import logging
from abc import abstractmethod, ABCMeta
import re
import chardet
import os
import openpyxl
requests.packages.urllib3.disable_warnings()
logging.basicConfig(level=logging.INFO, filemode='a', format="[%(levelname)s]%(asctime)s %(message)s")
# filename='./Logs/worklog.txt'

'''爬取基类'''
class Exploit(metaclass=ABCMeta):

    def __init__(self):
        self.source = 'BaseExploit'  #
        self.headers = {}
        self.target = ''  # 被攻击的目标

    @abstractmethod
    def write_file(self, web_lists, target, page):
        pass

    @abstractmethod
    def exploit(self, url_list):
        pass

    @abstractmethod
    def main(self):
        pass

    # 匹配文本中的子域名
    def matchSubdomain(self, domain, text):
        regexp = r'(?:[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?\.){0,}' + domain.replace('.', r'\.')
        result = re.findall(regexp, text, flags=re.I | re.S)
        if not result:
            return list()
        deal = map(lambda s: s.lower(), result)
        return list(deal)